//配置文件
//  属性配置
function createText(label, valid, types) {
  return {
    type: "input",
    valid,
    types,
    label,
  };
}
//表格组件//检查项共用createTable
function createTable(label,bool) {
  return {
    type: "table",
    label,
    isInspect:bool
  };
}
//radio/checkbox组件
function createRow(label) {
  return {
    type: "radio",
    label,
  };
}
//提示信息
function createHint(txt) {
  return {
    type: "texts",
    txt,
  };
}
function createSelect(label, valid, options) {
  return {
    type: "select",
    valid,
    label,
    options,
  };
}

//左侧拖拽组件  文字 word:title /subitle /undefined
const configList = [
  {
    label: "填表人组件",
    word: "title",
  },
  {
    label: "用于收集填表本人信息。",
    word: "subtitle",
  },
  {
    id: "1",
    label: "填表人姓名",
    tempType: "input",//服务小程序的字段：组件类型
    type: 'text',//服务小程序的字段：input类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    regex: "",//服务小程序的字段：input的regex
    key: "input",//决定form加载那种类型的组件
    //   render: (props) => <ElInput></ElInput>,
    props: {
      hint: createHint("用于搜集填写者本人姓名"),
      label: createText("姓名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "2",
    label: "填表人手机号",
    tempType: "input",//服务小程序的字段：组件类型
    type: 'number',//服务小程序的字段：input类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    regex: "",//服务小程序的字段：input的regex
    key: "input",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      hint: createHint("用于搜集填写者本人手机号"),
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "3",
    label: "填表身份证号",
    tempType: "input",//服务小程序的字段：组件类型
    type: 'text',//服务小程序的字段：input类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    regex: "/^(\d{17})(\d|X|x)$/",//服务小程序的字段：input的regex
    key: "input",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      hint: createHint("用于搜集填写者本人身份证号"),
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    label: "基础组件",
    word: "title",
  },
  {
    id: "4",
    label: "单行文本",
    tempType: "input",//服务小程序的字段：组件类型
    type: 'text',//服务小程序的字段：input类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    regex: "",//服务小程序的字段：input的regex
    key: "input",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "5",
    label: "多行文本",
    tempType: "textarea",//服务小程序的字段：组件类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    maxlength: 200, //服务小程序的字段：input最大输入长度
    regex: "",//服务小程序的字段：input的regex
    key: "input",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "6",
    label: "数字",
    tempType: "input",//服务小程序的字段：组件类型
    type: 'number',//服务小程序的字段：input类型
    placeholder: '请输入',//服务小程序的字段：input的placeholder
    value: "",//服务小程序的字段：input的value
    regex: "",//服务小程序的字段：input的regex
    key: "input",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  //小程序专属组件
  {
    id: "7",
    label: "表格",
    tempType: "table",//服务小程序的字段：组件类型
    value: [],//服务小程序的字段：table的value
    regex: "",//服务小程序的字段：input的regex
    key: "table",
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      value:createTable("标题列"),
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "8",
    label: "单选项",
    tempType: "radio",//服务小程序的字段：组件类型
    regex: "",//服务小程序的字段：input的regex
    key: "radio",
    option:[
      {
        label: "选项1",
        value:"1"
      },
      {
        label: "选项2",
        value:"2"
      },
    ],
    value:'',
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      option:createRow("选项"),
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "9",
    label: "多选项",
    tempType: "checkbox",//服务小程序的字段：组件类型
    regex: "",//服务小程序的字段：input的regex
    key: "checkbox",
    option:[
      {
        label: "选项1",
        value:"1"
      },
      {
        label: "选项2",
        value:"2"
      },
    ],
    value:'',
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      option:createRow("选项"),
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "10",
    label: "检查项",
    tempType: "inspect",//服务小程序的字段：组件类型
    key: "inspect",
    value:[],
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      value:createTable("检查项",true),
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "11",
    label: "定位",
    tempType: "location",//服务小程序的字段：组件类型
    key: "location",
    value:[],
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "12",
    label: "地址",
    tempType: "address",//服务小程序的字段：组件类型
    key: "address",
    value:[],
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "13",
    label: "手写签名",
    tempType: "signature",//服务小程序的字段：组件类型
    key: "signature",
    value:'',
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    label: "多媒体组件",
    word: "title",
  },
  {
    id: "14",
    label: "图片",
    tempType: "upload",//服务小程序的字段：组件类型
    key: "upload",
    type:'image',
    value:[],
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
  {
    id: "15",
    label: "视频",
    tempType: "upload",//服务小程序的字段：组件类型
    key: "upload",
    type:'video',
    value:[],
    //   render: (props) => <ElInput></ElInput>,
    props: {
      label: createText("字段名", [
        {
          required: true,
          message: "请输入",
          trigger: "blur",
        },
      ]),
      labelDetail: createText("字段说明"),//服务小程序的字段:组件描述
      propName: createText("属性名", [
        {
          required: false,
          message: "请输入",
          trigger: "blur",
        },
        {
          required:false,
          validator(rule,value,callback){
            //正则，英文数字下划线组成，字母开头
            let reg = /^[a-zA-Z][a-zA-Z0-9_]*$/;
            if (value&&!reg.test(value)) {
              return callback(new Error("属性名必须以字母开头，并且只能包含字母、数字和下划线"));
            } else {
              callback();
            }
          }
        }
      ]),
      mustFill: createSelect(
        "必填",
        [
          {
            required: true,
            message: "请选择必填",
            trigger: "change",
          },
        ],
        [
          { label: "必填", value: true },
          { label: "非必填", value: false },
        ]
      )
    },
  },
];

export default configList;
